﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using AimGameLibrary;
using AimGameEngine.EditorObject;

namespace AimGameEngine.NodeEditorObject
{
    public class NodeGravity : NodeBaseControl
    {
        public Dictionary<String, NodeObject> DictionaryObjectGravity;
        public float Strength;

        public NodeGravity(SpriteBatch inputspritebatch, Camera inputcamera, NodeData inputData
            , List<IDraw> MyListDraw, List<IUpdateMainTime> MyListUpdateTime, Dictionary<String, NodeObject> MyListObject, Dictionary<String, NodeObject> MyListType)
            : base(inputspritebatch, inputcamera, inputData, MyListDraw,MyListUpdateTime, MyListObject, MyListType)
	    {
            DictionaryObjectGravity = new Dictionary<string, NodeObject>();
            Strength = 0;

            Connecter inputBody = new Connecter(inputspritebatch, inputcamera, Syco.Input, NodeTypeValue.Body, this);
            ListConnectpoint.Add(inputBody);

            Connecter inputUpdate = new Connecter(inputspritebatch, inputcamera, Syco.Output, NodeTypeValue.Update, this);
            ListConnectpoint.Add(inputUpdate);
	    }

        public override void SetupInput(Connecter Thisconnect, Connecter connectOutput)
        {
            DictionaryObjectGravity.Add(connectOutput.MyNode.MyData.MyName, connectOutput.MyNode);
        }

        public override void ClearInput(Connecter ThisInputConnect, Connecter ThisConnectClear, string NameThisClear)
        {
            DictionaryObjectGravity.Remove(ThisConnectClear.MyNode.MyData.MyName);
        }

        public override void ShowProprety(ArrayList Temp, CallBack input)
        {
            base.ShowProprety(Temp, input);
            PropretyGravity propretygravity = new PropretyGravity(this);
            //propretygravity.Deactivate += new EventHandler(input.Deactivate);
            propretygravity.okButton.Click += new EventHandler(input.Deactivate);
            propretygravity.ShowDialog();
            
        }

        protected override Dictionary<string, NodeObject> GetDictionaryNode(Dictionary<string, NodeObject> TempNode)
        {
            return base.GetDictionaryNode(DictionaryObjectGravity);
        }

        public override void SaveData(System.Collections.ArrayList Thislist,SaveMode inputsavemode)
        {
            base.SaveData(Thislist,inputsavemode);

            Thislist.Add(Strength);
            Thislist.Add(DictionaryObjectGravity.Count);

            if (DictionaryObjectGravity.Count > 0)
                Thislist.Add(CreateData(DictionaryObjectGravity));
            else Thislist.Add("NULL");
        }

        public override void LoadData(Identification getdata, int IndexData)
        {
            base.LoadData(getdata, IndexData);

            if (getdata.Items.GetValue(IndexData + 1).GetType() == typeof(float))
            Strength = (float)getdata.Items.GetValue(IndexData + 1);
        }
    }
}
